﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<h2>日志显示</h2>

<div style="margin:25px">
    <form class="layui-form" action="">
        <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="start" placeholder="开始时间">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结束时间</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" id="end" placeholder="结束时间">
            </div>
        </div>
        <button class="layui-btn" lay-submit lay-filter="searchForm" onclick="search()">查询</button>
    </form>

    <table id="processTable" class="layui-table">
        <thead>
            <tr>
                <th>日志编号</th>
                <th>日志名称</th>
                <th>日志时间</th>
            </tr>
        </thead>
        <tbody>
            <!-- 工序列表数据将填充在这里 -->
        </tbody>
    </table>
</div>

<script>
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;

        // 执行一个laydate实例
        laydate.render({
            elem: '#start' // 指定元素
        });

        laydate.render({
            elem: '#end' // 指定元素
        });

        // 监听提交
        form.on('submit(searchForm)', function (data) {
            search(data.field.start, data.field.end);
            return false; // 阻止表单跳转
        });
    });
    $(function () {
        search(); // 页面加载时默认查询所有数据
    });


    function search(start, end) {
        var start = $("#start").val();
        var end = $("#end").val();
        console.log("开始时间：", start);
        console.log("结束时间：", end);
        $.post({
            url: '@ViewBag.Durian' + '/api/Process/Handle2',
            data: JSON.stringify({ start: start, end: end }),
            dataType: "json",
            async: false,
            contentType: "application/json",
            success: res => {
                console.log(res); // 修正控制台打印
                var count = "";
                $.each(res.data, function () {
                    count += `<tr>
                                        <td>${this.systemLogsId}</td>
                                        <td>${this.logeName}</td>
                                        <td>${this.logeTime.replace("T", " ").substring(0, 19)}</td>
                                      </tr>`;
                })
                $("tbody").html(count)
            }
        })
    }
</script>